DeleteBorderComponents
DeleteBorderComponents[image] replaces connected components adjacent to the border in a binary image image with background pixels.
DeleteBorderComponents[m] replaces components adjacent to the border in a label matrix m with 0.
Please visit the official Wolfram Language Reference for more details and examples on core symbols.